<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="/publico/template.xhtml">
        <ui:define name="content">
            <p:messages id="mensagem"/>

            <h:form id="formLote">
                <p:panel header="Pesagem dos Lotes">
                    <h:inputHidden value="#{loteBean.processo.id}"/>

                    <h:panelGrid columns="4">
                        <h:outputLabel for="massa" value="Massa: *"/>
                        <p:inputText id="massa" 
                                     value="#{loteBean.lote.massa}" 
                                     size="20">
                            <f:convertNumber integerOnly="true" 
                                             minIntegerDigits="1"  />
                        </p:inputText>

                        <h:outputLabel for="dataDePesagem" value="Data da Pesagem: *"/>
                        <p:calendar id="dataDePesagem"
                                    value="#{loteBean.lote.dataDePesagem}" 
                                    pattern="dd/MM/yyyy"  
                                    required="true"
                                    locale="pt"/>

                        <h:outputLabel for="cardapioSelect" value="Cardápio*:"/>
                        <p:selectOneMenu  id="cardapioSelect" 
                                          label="#{loteBean.lote.cardapio.nome}"
                                          value="#{loteBean.lote.cardapio}"
                                          converter="CardapioConversor">
                            <f:selectItems value="#{cardapioBean.cardapios}"
                                           var="c"
                                           itemLabel="#{c.nome}"
                                           itemValue="#{c}"/>
                        </p:selectOneMenu>

                        <h:outputLabel for="localOrigemSelect" value="Local*:"/>
                        <p:selectOneMenu id="localOrigemSelect" 
                                         value="#{loteBean.lote.localLote}"
                                         converter="LocalConversor">
                            <f:selectItems value="#{localBean.locais}"
                                           var="l"
                                           itemLabel="#{l.nome}"
                                           itemValue="#{l}"/>
                        </p:selectOneMenu>

                        <p:commandButton id="cbSalvar"
                                         action="#{loteBean.salvar}"
                                         value="Salvar"
                                         update=":dtLotes, :mensagem"/>
                    </h:panelGrid>
                </p:panel>
            </h:form>

            <h:form id="dtLotes">
                <p:panel header="Últimos Lotes">
                    <p:dataTable value="#{loteBean.processos}" 
                                 var="p"
                                 emptyMessage=" sem registros">
                        <p:column filterBy="#{p.id}" headerText="Número">
                            <h:outputText value="#{p.id}"/>
                        </p:column>

                        <p:column filterBy="#{p.lote.massa}" headerText="Massa">
                            <h:outputText value="#{p.lote.massa}"/>
                        </p:column>

                        <p:column filterBy="#{p.lote.dataDePesagem}" headerText="Data da Pesagem">
                            <h:outputText value="#{p.lote.dataDePesagem}">
                                <f:convertDateTime/>
                            </h:outputText>
                        </p:column>

                        <p:column filterBy="#{p.lote.cardapio.nome}" headerText="Cardapio">
                            <h:outputText value="#{p.lote.cardapio.nome}"/>
                        </p:column>

                        <p:column filterBy="#{p.lote.localLote.nome}" headerText="Local de Pesagem">
                            <h:outputText value="#{p.lote.localLote.nome}"/>
                        </p:column>

                        <p:column width="55">
                            <p:commandButton
                                id="cbalterar"
                                icon="ui-icon-pencil"
                                action="#{loteBean.alterar()}"
                                update=":formLote">
                                <f:setPropertyActionListener
                                    target="#{loteBean.processo}"
                                    value="#{p}"/>
                            </p:commandButton>
                        </p:column>

                        <p:column width="55">
                            <p:commandButton id="cbexcluir"
                                             icon="ui-icon-trash"
                                             action="#{loteBean.excluir()}"
                                             ajax="false"
                                             onclick="return confirm('Você tem certeza?')">
                                <f:setPropertyActionListener 
                                    target="#{loteBean.processo}"
                                    value="#{p}"/>
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
